/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.ec.product.entity.Specification
   Module Description   :

   Date Created      : 2009/11/21
   Original Author   : ellen.li
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.ec.product.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang.StringUtils;

import com.yaodian100.core.common.entity.BaseEntity;
import com.yaodian100.ec.common.EcConstant;

/**
 * @author ellen.li
 * 
 */
@Entity
@Table(name = "EC_SPECIFICATION")
public class Specification extends BaseEntity {

	/**
	 * serial version
	 */
	private static final long serialVersionUID = -3471456100244854888L;

	/**
	 * 規格編號
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "seq_ec_specification")
	@SequenceGenerator(name = "seq_ec_specification", sequenceName = "SEQ_EC_SPECIFICATION")
	@Column(name = "SPECIFICATION_ID")
	private Long specificationId;

	/**
	 * 對應商品
	 */
	@Column(name = "PRODUCT_ID", updatable = false)
	private String productId;

	/**
	 * 主規格名稱(例如:藍)
	 */
	@Transient
	private String mainSpecName;

	/**
	 * 次规格名称(例如：S)
	 */
	@Transient
	private String secondSpecName;

	/**
	 * 規格名稱(例如:XL)
	 */
	@Column(name = "SPECIFICATION_NAME", length = 100)
	private String specificationName;

	/**
	 * 規格料號(供應商自行管理之編號). 僅第一次建立商品主檔有效, 之後會移至Material對應多家供應商.
	 */
	@Column(name = "SPEC_CODE", length = 30)
	private String specCode;

	/**
	 * 規格條碼(國際標準bar code)
	 */
	@Column(name = "BAR_CODE", length = 30)
	private String barCode;

	/**
	 * 預留庫存, 供換貨使用.
	 */
	@Column(name = "REVERSE_INVENTORY")
	private int reverseInventory = 0;

	/**
	 * 訂單單筆最大可銷售數量
	 */
	@Column(name = "MAX_COUNT_PER_ORDER")
	private int maxCountPerOrder = 10;

	/**
	 * 訂單單筆最小可銷售數量
	 */
	@Column(name = "MIN_COUNT_PER_ORDER")
	private int minCountPerOrder = 1;

	/**
	 * 安全庫存量
	 */
	@Column(name = "SAFE_INVENTORY")
	private int safeInventory;

	/**
	 * 是否已刪除
	 */
	@Column(name = "IS_DELETE", length = 1)
	private String isDelete;

	/**
	 * 显示顺序(1~9,default 9 ，由大排到小，9最大)
	 */
	@Column(name = "SHOW_SEQ")
	private int showSeq = 1;

	/** 熱銷數 */
	@Column(name = "HOTSALE_INVENTORY")
	private int hotSaleInventory = 0;

	/**
	 * 规格状态
	 */
	@Column(name = "SPEC_STATUS", length = 2)
	private String specStatus;

	/**
	 * @return the barCode
	 */
	public String getBarCode() {
		return barCode;
	}

	public int getHotSaleInventory() {
		return hotSaleInventory;
	}

	/**
	 * @return the isDelete
	 */
	public String getIsDelete() {
		return isDelete;
	}

	/**
	 * @return the maxCountPerOrder
	 */
	public int getMaxCountPerOrder() {
		return maxCountPerOrder;
	}

	/**
	 * @return the minCountPerOrder
	 */
	public int getMinCountPerOrder() {
		return minCountPerOrder;
	}

	/**
	 * @return the productId
	 */
	public String getProductId() {
		return productId;
	}

	/**
	 * @return the reverseInventory
	 */
	public int getReverseInventory() {
		return reverseInventory;
	}

	/**
	 * @return the safeInventory
	 */
	public int getSafeInventory() {
		return safeInventory;
	}

	public int getShowSeq() {
		return showSeq;
	}

	/**
	 * @return the specCode
	 */
	public String getSpecCode() {
		return specCode;
	}

	/**
	 * @return the specificationId
	 */
	public Long getSpecificationId() {
		return specificationId;
	}

	/**
	 * @return the specificationName
	 */
	public String getSpecificationName() {
		if (StringUtils.isNotBlank(specificationName)) {
			specificationName = StringUtils.replaceEach(specificationName, new String[] { "\n", "\r" },
					new String[] { " ", " " }).trim();
		}
		return specificationName;
	}

	public String getSpecStatus() {
		return specStatus;
	}

	/**
	 * @param barCode the barCode to set
	 */
	public void setBarCode(String barCode) {
		this.barCode = barCode;
	}

	public void setHotSaleInventory(int hotSaleInventory) {
		this.hotSaleInventory = hotSaleInventory;
	}

	/**
	 * @param isDelete the isDelete to set
	 */
	public void setIsDelete(String isDelete) {
		this.isDelete = isDelete;
	}

	/**
	 * @param maxCountPerOrder the maxCountPerOrder to set
	 */
	public void setMaxCountPerOrder(int maxCountPerOrder) {
		this.maxCountPerOrder = maxCountPerOrder;
	}

	/**
	 * @param minCountPerOrder the minCountPerOrder to set
	 */
	public void setMinCountPerOrder(int minCountPerOrder) {
		this.minCountPerOrder = minCountPerOrder;
	}

	/**
	 * @param productId the productId to set
	 */
	public void setProductId(String productId) {
		this.productId = productId;
	}

	/**
	 * @param reverseInventory the reverseInventory to set
	 */
	public void setReverseInventory(int reverseInventory) {
		this.reverseInventory = reverseInventory;
	}

	/**
	 * @param safeInventory the safeInventory to set
	 */
	public void setSafeInventory(int safeInventory) {
		this.safeInventory = safeInventory;
	}

	public void setShowSeq(int showSeq) {
		this.showSeq = showSeq;
	}

	/**
	 * @param specCode the specCode to set
	 */
	public void setSpecCode(String specCode) {
		this.specCode = specCode;
	}

	/**
	 * @param specificationId the specificationId to set
	 */
	public void setSpecificationId(Long specificationId) {
		this.specificationId = specificationId;
	}

	/**
	 * @param specificationName the specificationName to set
	 */
	public void setSpecificationName(String specificationName) {
		if (StringUtils.isNotBlank(specificationName)) {
			specificationName = StringUtils.replaceEach(specificationName, new String[] { "\n", "\r" },
					new String[] { " ", " " }).trim();
		}
		this.specificationName = specificationName;
	}

	public void setSpecStatus(String specStatus) {
		this.specStatus = specStatus;
	}

	/**
	 * 取得主规格名称
	 * 
	 * @return
	 */
	public String getMainSpecName() {
		if (StringUtils.isBlank(specificationName)) {
			mainSpecName = "";
		} else if (StringUtils.indexOf(specificationName, EcConstant.SPEC_SYMBOL) == -1) {
			mainSpecName = "综合";
		} else {
			mainSpecName = StringUtils.split(specificationName, EcConstant.SPEC_SYMBOL)[0];
		}
		return mainSpecName;
	}

	public void setMainSpecName(String mainSpecName) {
		this.mainSpecName = mainSpecName;
	}

	/**
	 * 取得次规格名称
	 * 
	 * @return
	 */
	public String getSecondSpecName() {
		if (StringUtils.isBlank(specificationName)) {
			secondSpecName = "";
		} else if (StringUtils.indexOf(specificationName, EcConstant.SPEC_SYMBOL) == -1) {
			secondSpecName = specificationName;
		} else {
			secondSpecName = StringUtils.split(specificationName, EcConstant.SPEC_SYMBOL)[1];
		}
		return secondSpecName;
	}

	public void setSecondSpecName(String secondSpecName) {
		this.secondSpecName = secondSpecName;
	}

	@Transient
	public String getSpecId() {
		if (null != specificationId && specificationId > 0) {
			return specificationId.toString();
		} else {
			return "0";
		}
	}
}
